import axios from 'axios'
import apis from './apis'
import qs from 'qs'
import {Toast} from 'vant'
const service = axios.create({
  // baseURL: process.env.NODE_ENV==='development' ? '/woa' : 'http://192.168.33.241:10000/woa',
  baseURL: 'http://192.168.33.241:10000/woa',
})
const extraUrls = ['/v1/position/applyFor']
service.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
  console.log('config',config)
  if(extraUrls.indexOf(config.url)==-1){
    config.data = qs.stringify(config.data)
  }

  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});

// 添加响应拦截器
service.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  // console.log('res',response)
  if(response.data.code===1){
    return Promise.resolve(response.data)
  }else {
    return Promise.reject(response.data)
  }
  
}, function (error) {
  // 对响应错误做点什么
  // console.log('error',error)
  return Promise.reject(error);
});

//岗位相关
export const getPositionList = ()=>{
  return service.get(apis.positionSelect)
}
export const getPositionDetailById = (id)=>{
   return service.get(apis.positionDetail+'/'+id)
}
export const positionApplyFor = (data,id)=>{
  return service.post(apis.positionApplyFor,data,{
    // headers:{'Content-Type': 'multipart/form-data'},
    params:{positionId:id},
    onUploadProgress:(event)=>{
      console.log('event',event)
      Toast('申请中')
    }
  })
}


